<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>配置项</title>
<link href="<%=request.getContextPath()%>/css/Default.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/ui.jqgrid.css"
	rel="stylesheet" type="text/css"></link>
<link href="<%=request.getContextPath()%>/css/redmond/jquery-ui-1.8.14.custom.css"
	rel="stylesheet" type="text/css"></link>
<link href="<%=request.getContextPath()%>/css/Dialog.css"
	rel="stylesheet" type="text/css"></link>
<script src="<%=request.getContextPath()%>/scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/scripts/HRM.js" type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jqgrid/i18n/grid.locale-cn.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jqgrid/jquery.jqGrid.src.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery-ui-1.8.14.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery.form.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Dialog.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/DataGrid.js"
	type="text/javascript"></script>
<script>
$().ready(function() {//加载配置项列表
	dataGridID='configDataGrid';
	var path='<%=request.getContextPath()%>/config.do?method=getConfigs';
	var params={
		'path':path,
		colNames : [ 'ID',
						'配置项代码', '配置项名称',
						'创建人', '创建时间',
						'备注' ],
		colModel : [
					{
						name : 'id',
						index : 'id',
						width : 10
					//百分比
					},
					{
						name : 'code',
						index : 'code',
						width : 10
					},
					{
						name : 'name',
						index : 'name',
						width : 10
					},
					{
						name : 'userName',
						index : 'userName',
						width : 15
					},
					{
						name : 'updateTime',
						index : 'updateTime',
						width : 15
					},
					{
						name : 'remark',
						index : 'remark',
						width : 40
					}]
	};
	initJQGrid(params,dataGridID);
	
	$("#newConfigBtn").die('click').live('click',function(){
		var params={
				  'title':'新增配置项',
				  'url':$(this).attr('url'),
				  'width':500,
				  'height':360,
				  btnSucFunc:function(){
					  $("#configDataGrid").trigger("reloadGrid");
				  }
				 };
		createIframeDialog(params);
	});
	$('#editConfigBtn').die('click').live('click',function(){
		var configids; 
		configids = $("#configDataGrid").jqGrid('getGridParam','selarrrow');
		if(configids.length<=0){
			createAlertDialog('提示信息','请选择一个配置项进行编辑!');
			return false;
		}
		if(configids.length>1){
			createAlertDialog('提示信息','只能选择一个配置项进行编辑!');
			return false;
		}
		var params={
				  'title':'编辑配置项',
				  'url':$(this).attr('url')+"&id="+configids,
				  'width':500,
				  'height':360,
				  btnSucFunc:function(){
					  $("#configDataGrid").trigger("reloadGrid");
				  }
				 };
		createIframeDialog(params);
	});
	$('#delConfigBtn').die('click').live('click',function(){
		var configids = $("#configDataGrid").jqGrid('getGridParam','selarrrow');
		if(configids.length<=0){
			createAlertDialog('提示信息','请至少选择一个配置项进行删除!');
			return false;
		}
		
		var msg='确认删除id为(<span style="color:red;font-weight:bold">'+configids+'</span>)的配置项?';
		createConfirmDialog('确认删除配置项?',msg,function(){
			$.ajax({
				type : "GET",
				url : '<%=request.getContextPath()%>/config.do?method=deleteConfigById&configids='+configids,
				dataType : "json",
				success : function(data) {
					if (data['status'] == 'ERROR') {
						createAlertDialog('提示信息','删除配置项失败!');
					} else {
						createAlertDialog('提示信息','删除配置项成功!',function(){
							$("#configDataGrid").trigger("reloadGrid");
						});
					}
				},
				error : function() {
					createAlertDialog('提示信息','网络繁忙,请稍后再试!');
				}
			});
		});
	});
	$(".configManageLink").die('click').live('click',function(){
		var params={
				  'title':'配置项',
				  'url':"./ConfigItemManage.jsp?type="+$(this).attr('name'),
				  'width':800,
				  'height':500,
				  confirmBtn:false
				 };
		createIframeDialog(params);
	});
});
	function delKeyWord() {
		$("#SearchConfigName").val('');
	}
	function blurKeyWord() {
		if ($("#SearchConfigName").val().trim() == '') {
			$("#SearchConfigName").val('请输入配置项名或真实姓名');
		}
	}
	function doSearch(){
		if($('#SearchConfigName').val().trim()=='请输入配置项名或真实姓名'){
			createAlertDialog('提示信息','搜索关键字不能为空!');
			return false;
		}
		var path='<%=request.getContextPath()%>/config.do?method=getConfigsByName&name='+$('#SearchConfigName').val().trim();
		$("#"+dataGridID).jqGrid('setGridParam', {
			url : path,
			ajaxGridOptions:{
				error:function(){
					createAlertDialog('提示信息','网络繁忙,请稍后再试!');
				}
			}
		}).trigger("reloadGrid");//重新设置url重新加载数据
	}
</script>
</head>
<body>
<div class="dataGridTopDiv">
<table style="width:99%;border-collapse: separate; border-spacing: 6px;cellpadding:0;cellspacing:6;border:0px solid #dddddd;">
			<tr valign="top">
				<td>
					<table width="100%" border="0" cellspacing="0" cellpadding="6"
						id="tableArea" class="blockTable">
						<tr>
							<td valign="middle" class="blockTd"><img
								src="<%=request.getContextPath()%>/images/icons/icon018a1.gif" />
								配置项列表</td>
						</tr>
						<tr>
							<td style="padding: 0 8px 4px;"><a id="newConfigBtn"
								href='javascript:void(0);' url="./ConfigAdd.jsp" class='zPushBtn' tabindex='-1'><img
									src="<%=request.getContextPath()%>/images/icons/icon018a2.gif" /><b>新建&nbsp;</b></a>
								<a id="editConfigBtn" url="<%=request.getContextPath()%>/config.do?method=updateConfig" 
									href='javascript:void(0);' class='zPushBtn'><img
									src="<%=request.getContextPath()%>/images/icons/icon018a4.gif" /><b>编辑&nbsp;</b></a>
								<a href='javascript:void(0);' class='zPushBtn' id='delConfigBtn'><img
									src="<%=request.getContextPath()%>/images/icons/icon018a3.gif" /><b>删除&nbsp;</b></a>
								<div style="float: right; white-space: nowrap;">
									<input style="font-style ': 'italic';" name="SearchConfigName"
										type="text" id="SearchConfigName" value="请输入配置项名称"
										onFocus="delKeyWord();" onBlur="blurKeyWord();"
										style="width: 150px"> <input type="button"
										name="Submitbutton" id="Submitbutton" value="查询"
										onClick="doSearch(this)">
								</div></td>
						</tr>
						<tr>
							<td id="dataGridTd"
								style="padding-top: 0px; padding-left: 6px; padding-right: 6px; padding-bottom: 8px;">
								<table id="configDataGrid" width=100% class="dataGridTable" ></table>
								<div id="pager"></div> 
							</td>
						</tr>
					</table>
				</td>
			</tr>
			</table>
	</div>
</body>
</html>
